package com.logistics.pick.controller;


import com.logistics.pick.entity.model.PickQuery;
import com.logistics.pick.entity.model.PickSave;
import com.logistics.pick.service.PickDetailService;
import com.logistics.pick.service.PickService;
import com.logistics.utils.aspect.annotation.LoggerListener;
import com.logistics.utils.constants.LoggerMethod;
import com.logistics.utils.exception.MessageException;
import com.logistics.utils.response.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 拣配单 前端控制器
 * </p>
 *
 * @author kaihan.wang
 * @since 2024-06-28
 */
@RestController
@RequestMapping("lgs/pick")
public class PickController {

    @Autowired
    private PickService pickService;

    @Autowired
    private PickDetailService pickDetailService;

    /**
     * 根据id查询拣配单
     * @param id
     * @return
     */
    @GetMapping("/pickInfo/{id}")
    @LoggerListener(businessName = "根据ID查询拣配单信息", methodName = LoggerMethod.SEARCH)
    public ResponseEntity getById(@PathVariable("id") String id) throws MessageException {
        return ResponseUtil.success(pickService.getPickOrderById(id));
    }

    /**
     * 完成拣配
     * @param params
     * @return
     */
    @PutMapping("/finishPick")
    @LoggerListener(businessName = "完成拣配", methodName = LoggerMethod.SAVE)
    public ResponseEntity finishPick(@RequestBody PickSave params) throws MessageException {
        pickService.finishPick(params);
        return ResponseUtil.success();
    }

    /**
     * 根据 查询条件(拣配单号，erp单据号，状态)查找拣配单信息
     * @param params
     * @return
     */
    @PutMapping("/pickInfo")
    @LoggerListener(businessName = "根据 查询条件查找拣配单信息", methodName = LoggerMethod.SEARCH)
    public ResponseEntity getByFilter(@RequestBody PickQuery params) throws MessageException {
        return ResponseUtil.success(pickService.getPickInfoByFilter(params));
    }

    /**
     * 根据 拣配单ID查找拣配详细信息
     * @param param
     * @return
     */
    @PostMapping("/pickDetailInfo")
    @LoggerListener(businessName = "根据拣配单ID查找拣配详细信息", methodName = LoggerMethod.SEARCH)
    public ResponseEntity getDetailByPickId(@RequestBody PickQuery param) throws MessageException {
        return ResponseUtil.success(pickDetailService.getPickDetailInfoByPickId(param));
    }

    /**
     * 获取拣配单状态filter信息
     * @param
     * @return
     */
    @GetMapping("/statusFilters")
    @LoggerListener(businessName = "获取拣配单状态filter信息", methodName = LoggerMethod.SEARCH)
    public ResponseEntity getStatusFilters() throws MessageException {
        return ResponseUtil.success(pickService.getPickStatusFilter());
    }

}

